//
//  XGStatusPostArticleTableViewCell.swift
//  TodayNews
//
//  Created by monkey on 2020/2/24.
//  Copyright © 2020 itcast. All rights reserved.
//

import UIKit
import YYText

/// 文章视图高度
public let kStatusArticleViewHeight: CGFloat = 80

// MARK: - XGStatusPostArticleTableViewCell

class XGStatusPostArticleTableViewCell: XGBaseStatusTableViewCell
{
    override var statusViewModel: XGStatusViewModel? {
        didSet {
            articleView.titleLabel.text = statusViewModel?.articleOrVideoTitle
            articleView.playIconImageView.isHidden = statusViewModel?.mediaType != .postVideo
            if let url = statusViewModel?.articleOrVideoThumbUrl {
                articleView.iconImageView.kf.setImage(with: URL(string: url))
            }
        }
    }
    
    override func setUpUI()
    {
        super.setUpUI()
        
        addSubview(articleView)
        articleView.snp.makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp.bottom).offset(10)
            make.left.right.equalToSuperview()
            make.height.equalTo(kStatusArticleViewHeight)
        }
    }
    
    /// 文章视图
    private lazy var articleView = XGStatusActicleView()
}

// MARK: - XGStatusActicleView

private class XGStatusActicleView: UIView
{
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.90, alpha: 1)
        addSubview(titleLabel)
        addSubview(iconImageView)
        addSubview(playIconImageView)
        iconImageView.contentMode = .center
        iconImageView.clipsToBounds = true
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews()
    {
        super.layoutSubviews()
        
        let imageWidth: CGFloat = 120
        iconImageView.frame = CGRect(x: bounds.width - 10 - imageWidth, y: 0, width: imageWidth, height: bounds.height)
        titleLabel.frame = CGRect(x: 10, y: 5, width: bounds.width - imageWidth - 30, height: bounds.height - 10)
        playIconImageView.center = iconImageView.center
    }
    
    /// 内容
    private(set) lazy var titleLabel = UILabel(text: "测试", textColor: UIColor.darkGray, fontSize: 15, textAlignment: .left)
    /// 图片
    private(set) lazy var iconImageView = UIImageView()
    /// 播放按钮
    private(set) lazy var playIconImageView = UIImageView(image: UIImage(named: "smallvideo_all_32x32_"))
}
